package group.igfd.manager.biz.service.impl;

import org.springframework.stereotype.Service;

import java.lang.reflect.Array;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import group.igfd.manager.biz.dao.QuotesDao;
import group.igfd.manager.biz.entity.QuotesEntity;
import group.igfd.manager.biz.service.QuotesService;


@Service("quotesService")
public class QuotesServiceImpl extends ServiceImpl<QuotesDao, QuotesEntity> implements QuotesService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<QuotesEntity> page = this.selectPage(
                new Query<QuotesEntity>(params).getPage(),
                new EntityWrapper<QuotesEntity>()
        );

        return new PageUtils(page);
    }



    @Override
    public QuotesEntity getQuotesInfo(int pid){
        /*EntityWrapper<QuotesEntity> ew = new EntityWrapper<>();
        ew.eq("pid", pid);
        ew.setSqlSelect("price", "pid", "days", "status", "created_at");
        QuotesEntity entity = this.selectOne(ew);

        if(null == entity){
            entity = new QuotesEntity();
            entity.setPrice("");
            entity.setPid("");
            entity.setDays("");
            entity.setStatus(0);
            entity.setCreatedAt("");
        }*/

        QuotesEntity quotesEntity = null;

        //已经确认报价
        EntityWrapper<QuotesEntity> ew = new EntityWrapper<>();
        ew.eq("pid", pid);
        ew.eq("status",2);
        quotesEntity = this.selectOne(ew);
        if (quotesEntity != null) {
            return quotesEntity;
        }

        //买手报价中
        EntityWrapper<QuotesEntity> ew2 = new EntityWrapper<>();
        ew2.eq("pid", pid);
        ew2.eq("status",1);
        quotesEntity = this.selectOne(ew2);
        if (quotesEntity != null) {
            return quotesEntity;
        }

        //报价已失效
        EntityWrapper<QuotesEntity> ew3 = new EntityWrapper<>();
        ew3.eq("pid", pid);
        ew3.eq("status",3);
        quotesEntity = this.selectOne(ew3);
        if (quotesEntity != null) {
            return quotesEntity;
        }

        return quotesEntity;
    }

}
